// backend/server.js
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const { exec } = require('child_process');

const app = express();
const port = 3000;

app.use(cors());

app.use(bodyParser.json());

app.post('/send-email', (req, res) => {
    const { smtpServer, username, password, to, subject, body } = req.body;

    const command = `./email "${smtpServer}" "${username}" "${password}" "${to}" "${subject}" "${body}"`;

    exec(command, (error, stdout, stderr) => {
        if (error) {
            return res.status(500).json({ status: 'error', message: stderr });
        }
        res.status(200).json({ status: 'success', message: stdout });
    });
});

app.listen(port, () => {
    console.log(`Server is running on http://localhost:${port}`);
});
